package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.ActivityDao;
import com.xbongbong.pro.domain.entity.ActivityEntity;
import com.xbongbong.saas.model.ActivityModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 公告
 * @Author: hongxiao
 * @date: 2019-03-25 14:14
 * @since v1.0
 */
@Service("activityModel")
public class ActivityModelImpl implements ActivityModel {

    @Resource
    private ActivityDao activityDao;

    @Override
    public Integer insert(ActivityEntity entity) {
        long now = DateUtil.getInt();
        entity.setUpdateTime(now);
        entity.setAddTime(now);
        entity.setDel(DelEnum.NORMAL.getDel());
        return activityDao.insert(entity);
    }

    @Override
    public Integer update(ActivityEntity entity) {
        entity.setUpdateTime((long)(DateUtil.getInt()));
        return activityDao.update(entity);
    }

    @Override
    public Integer save(ActivityEntity entity) {
        if(entity.getId() == null || Objects.equals(0L, entity.getId())) {
            return activityDao.insert(entity);
        }
        return activityDao.update(entity);
    }

    @Override
    public Integer deleteByKey(Long key) {
        return activityDao.deleteByKey(key);
    }

    @Override
    public ActivityEntity getByKey(Long key) {
        return activityDao.getByKey(key);
    }

    @Override
    public List<ActivityEntity> findEntitys(Map<String ,Object> param) {
        return activityDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String ,Object>  param) {
        return activityDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }
}
